package com.cbl.v.ssczs.view.activity;

import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.cbl.v.ssczs.R;
import com.cbl.v.ssczs.mode.net.HttpRequestForResponse;
import com.cbl.v.ssczs.mode.net.MyState;
import com.cbl.v.ssczs.mode.util.DialogUtils;
import com.cbl.v.ssczs.mode.util.NetStatusUtil;

import butterknife.BindView;
import butterknife.OnClick;

public class WelcomeActivity extends com.cbl.v.ssczs.view.activity.BaseActivity {
    @BindView(R.id.image)
    ImageView image;
    private Handler handler;

    @Override
    protected int getLayout() {
        return R.layout.activity_welocme;
    }

    @Override
    public void initView() {

        hideTitleBar();
        handler = new Handler();
    }

    @Override
    public void initData() {
        HttpRequestForResponse.getData(this, MyState.requestOne);
    }

    @Override
    public void initListener() {

    }

    @OnClick(R.id.image)
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.image:
                if (!NetStatusUtil.isConnected(getContext())) {
                    Toast.makeText(this, "请检查网络连接！", Toast.LENGTH_SHORT).show();
                    DialogUtils.showErrorWithStatus("无网络连接！请检查网络", this);
                } else {
                    startNewActivity(com.cbl.v.ssczs.view.activity.ChartActivity.class);
                }
                break;
        }
        super.onClick(view);
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (!NetStatusUtil.isConnected(getContext())) {
            Toast.makeText(this, "请检查网络连接！", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void dataBack(Object data, int order) {
        DialogUtils.showWithStatus(getContext());
        switch (order) {
            case MyState.requestOne:
                final String url = (String) data;
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        DialogUtils.disMissDialog();
                        if (!TextUtils.isEmpty(url)) {
                            startNewActivity(com.cbl.v.ssczs.view.activity.MainActivity.class, url);
                        } else {
                            startNewActivity(com.cbl.v.ssczs.view.activity.ChartActivity.class);
                        }
                        finish();
                    }
                }, 500);
                break;
        }
        super.dataBack(data, order);
    }

    @Override
    public void upDateApp(Object data) {
        super.upDateApp(data);
    }
}
